package com.sopt.friends;

import com.sopt.friends.db.FriendsDBHelper;
import com.sopt.friends.db.Constants.FriendsDB;
import com.sopt.friends.sub.TabContentsActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SettingActivity extends Activity {
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		
		Button backButton = (Button)findViewById(R.id.backButton);
		backButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}
	private void doInit(){
		FriendsDBHelper dbhelper = new FriendsDBHelper(SettingActivity.this);
		SQLiteDatabase db = dbhelper.getReadableDatabase();
		dbhelper.forceRegenerate(db);
		
		Intent intent = new Intent(SettingActivity.this,MainActivity.class);
		startActivity(intent);
	}
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		Button initButton = (Button)findViewById(R.id.initButton);
		initButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				AlertDialog.Builder ad = new AlertDialog.Builder(SettingActivity.this);
				ad.setTitle(getResources().getString(R.string.warningdelete));
				ad.setPositiveButton("OK",new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						doInit();
					}
				});
				ad.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						
					}
				});
				ad.create().show();
				
			}
		});
	}
}
